	window.onload=function(){
		//背景轮换
		var pics=new Array(3)
		pics[0]="url(pic/back1.png)";
		pics[1]="url(pic/back2.png)";
		pics[2]="url(pic/back3.png)";
		var index=0;
		var main=document.getElementById("main");
		function change_backimg(){
			index=(index+1)%3;
			main.style.backgroundImage=pics[index];
		}
		setInterval(change_backimg,10000);
		
		
		
		
		//登录链接事件
		document.getElementById("login").onclick=function(){
		document.getElementById("max").style.display="block";
		document.getElementsByTagName("main")[0].style.filter="blur(4px) contrast(.8)";
		}
		
		
		
		
		//注册按钮跳转到注册页面
		document.getElementById("bt_register").onclick=function(){
			window.open("register.html");
		}
		
		
		
		//导航栏hover下拉事件
		var l3=document.getElementById("l3");
		l3.onmouseover=function(){
		document.getElementById("down3").style.display="block";
		}
		l3.onmouseout=function(){
		document.getElementById("down3").style.display="none";
		}
		
		
		
		
		//登录按钮向服务器发送数据
		document.getElementById("bt_login").onclick=Login;
		
		
		
		
		//获取验证码图片
		document.getElementById("changeconf").onclick=GetConImg;
		GetConImg();
		
		
		
		//搜索按钮点击事件
		document.getElementById("bt_search").onclick=function(){
			window.location="result.html";
		}
	}
	function GetConImg(){
		document.getElementById("confirmImg").src="/baike/sdubaike/getCheckCodeImage?"+Math.random();
	}
	function Login(){
		var username=document.getElementById("username").value;
		var password=document.getElementById("password").value;
		var confirm=document.getElementById("checkcode").value;
		var data="username="+username+"&password="+password+"&checkCode="+confirm;
		var request=createRequest();
		if(request==null)
			alter("无法创建请求");
		else{
			request.onreadystatechange=function()
			{
			if (request.readyState==4 && request.status==200)
				{
					var restext=request.responseText;
					if(restext=="success")
						document.getElementById("errormsg").innerHTML="登录成功";
					else{
						switch(restext)
						{
						case "wrongCheckCode":
							document.getElementById("errormsg").innerHTML="验证码错误";
							break;
						case "notExist":
							document.getElementById("errormsg").innerHTML="用户名不存在";
							break;
						case "notAct":
							document.getElementById("errormsg").innerHTML="用户未激活";
							break;
						case "notMatch":
							document.getElementById("errormsg").innerHTML="密码错误";
							break;
						}
						GetConImg();
					}
				}
			}
			request.open("POST","/baike/sdubaike/Login",true);
			request.setRequestHeader("Content-type","application/x-www-form-urlencoded");
			request.send(data);
			}

			
	}